# -*- coding: utf-8 -*-
# @Time : 2025/11/03 10:59:11
# @Desc : 自动创建spec文件
# @Author : Sean
# @File   : build_spec.py
from utils.common import get_resource_path
from config.config import Config


def create_spec():
    """
    @说明:自动创建spec是打包文件的配置文件
    @参数:
    @参数:
    @时间:2025/11/03 11:00:51
    @作者:Sean
    @返回:
    """
    hooksconfig_dict = {}
    binaries = Config.win7_need if Config.isWin7 else []
    file = f"""
    # -*- mode: python ; coding: utf-8 -*-


a = Analysis(
    ['main.py'],
    pathex=[],
    binaries={binaries},
    datas={Config.add_folder},
    hiddenimports=[],
    hookspath=[],
    hooksconfig={hooksconfig_dict},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

splash = Splash(
    'icon/loading.png',
    binaries=a.binaries,
    datas=a.datas,
    text_pos=None,
    text_size=12,
    minify_script=True,
    always_on_top=True,
)

exe = EXE(
    pyz,
    a.scripts,
    splash,
    [],
    exclude_binaries=True,
    name='{Config.appPackage}',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    version='file_version_info.txt',
    # contents_directory打包时不要_internal文件夹
    contents_directory='.',
    icon={Config.icon},
)
coll = COLLECT(
    exe,
    a.binaries,
    a.datas,
    splash.binaries,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='{Config.appPackage}',
)

    """
    with open(get_resource_path("main.spec"), "w+", encoding="utf-8") as f:
        f.write(file)


create_spec()
